package chapter03.Demo3;
/**
 * 1. this 关键字
 * 类this指类本身
 * this可以调用是习惯和方法
 * 2. static 关键字
 * 静态属性 一个地方修改类中该静态属性 其他类的对象跟则会变化
 */
class Student{
    String id; //学生学号
    private  String name; //学生姓名
    private  int age; // 年龄 私有属性
    private  int gender; // 性别 0男 1女

    public String dep = "信息工程系";
    public static String hobby = "健身";

    public Student(){
    }
    public Student(String ID){
        id = ID;
    }
    public Student(String ID, String n) {
        id = ID;
        name = n;
    }
    public void setName(String name){
         //name = name; //错误写法 将形参 name复制给学生类属性name
        this.name = name;// this指该类本身
    }
    public String getName(){
        return name;
    }
    public void setAge(int age) {
        // 将形参a改为形参age
        if (age < 0  ||  age > 150){
            System.out.println("输入年龄非法");
        }else {
            this.age = age;
        }
    }
    public void setGender(String g) {
        if (g.equals("男")) {
            gender = 0;
        }else {
            gender = 1;
        }
    }
    public String getGender(){
        if (gender == 0){
            return "男";
        }else {
            return "女";
        }
    }
}
public class Demo3 {
    public static void main(String[] args) {
        Student stu1 = new Student();
        stu1.setName("猪小明");
        stu1.setAge(20);
        System.out.println(stu1.dep);
        Student stu2 = new Student();
        System.out.println(stu2.dep);
        System.out.println("*********");
        stu1.dep = "宇宙系";
        System.out.println(stu1.dep);
        System.out.println(stu2.dep);
        System.out.println("查看爱好");
        System.out.println(stu1.hobby);
        System.out.println(stu2.hobby);
        System.out.println("**********");
        stu2.hobby = "抽烟";
        System.out.println(stu1.hobby);
        System.out.println(stu2.hobby);
    }
}
